<?php

function &load_class($name, $core = 0)
{
	static $objects = array();
	
	if (isset($objects[$name]))
		return $objects[$name];
	
	require (($core)?CORE.'/':SYSTEM.'/').$name.'.class.php';
	
	$objects[$name] = new $name;
	return $objects[$name];
}


function &load_model($name)
{
	static $models = array();
	
	if (isset($models[$name]))
		return $models[$name];
	
	require (($core)?CORE.'/':SYSTEM.'/').'models/'.$name.'.class.php';
	
	$models[$name] = new $name;
	return $models[$name];
}

function config_item($key)
{
	static $cfg = array();
	if (!isset($cfg[$key]))
	{
		require SYSTEM.'/config.inc.php';
		$cfg[$key] =& $config[$key];
	}
	
	return $cfg[$key];
}

//make string url-friendly
function htmlize($string)
{
	$bad = 		array('_','\'','"','>','<',',','.','/','?','>','<',':',';','{','[','}',']','+','=',' ',')','(','*','&','^','%','$','#','@','!','`','~','ą','Ą','č','Č','ę','Ę','ė','Ė','į','Į','š','Š','ų','Ų','ū','Ū','ž','Ž');
	$replace = 	array('-',''  ,'' ,'' ,'' ,'' ,'' ,'-' ,'' , '','' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'-','' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'a','a','c','c','e','e','e','e','i','i','s','s','u','u','u','u','z','z');
	$string = mb_strtolower($string, 'utf8');
	$string = str_replace($bad,$replace,$string);
	$string = preg_replace('/\s+/','-',$string);
	
	$string = preg_replace('/-+/','-',$string);
	
	return $string;
}

?>